﻿using System;
using System.Linq;
using FluentValidation;

namespace LINQPad.OpenAccess.UI.ViewModel.Validators
{
    /// <summary>
    ///   <see cref="MsSqlConnectionSettingsViewModel" /> validator.
    /// </summary>
    public class MsSqlConnectionSettingsViewModelValidator : ConnectionSettingsViewModelValidator<MsSqlConnectionSettingsViewModel>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MsSqlConnectionSettingsViewModelValidator" /> class.
        /// </summary>
        public MsSqlConnectionSettingsViewModelValidator( )
        {
            this.RuleFor( e => e.ServerName )
                .NotEmpty( )
                .WithMessage( "no server set !" );

            this.RuleFor( e => e.DatabaseName )
                .NotEmpty( )
                .WithMessage( "no database set !" );

            this.RuleFor( e => e.UserName )
                .NotEmpty( )
                .WithMessage( "no user name set !" )
                .Unless( e => e.UseWindowsAuthentication );

            this.RuleFor( e => e.Password )
                .NotEmpty( )
                .WithMessage( "no password set !" )
                .Unless( e => e.UseWindowsAuthentication );
        }
    }
}
